package com.cashmama.market.api.domain.vo.order;

import com.cashmama.market.api.domain.vo.RequestLocalInfo;
import com.cashmama.market.api.infras.enums.JumpRouterEnum;
import com.cashmama.market.api.infras.utils.DateUtil;
import com.cashmama.market.api.infras.utils.DecimalUtils;
import com.google.common.collect.Lists;
import com.qianli.cashmama.trade.client.offer.response.OfferResponse;
import com.qianli.cashmama.trade.common.enums.TradeBorrowDurationEnum;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @program: market-api
 * @description 订单确认信息
 * @author: frank
 * @create: 2019-12-24 18:12
 **/
public class OrderConfirmDetailVO {

    private String merchantCode;
    private String productCode;
    private String categoryName;
    private String categoryDesc;
    private String categoryLogo;
    /**
     * 客户端权限获取信息
     */
    private PermissionsInfo permissionsInfo;
    List<OrderFieldDetail> orderViewInfo = Lists.newArrayList();
    List<UsageOfLoan> usageOfLoanList = Lists.newArrayList();
    List<OrderFieldDetail> otherInfo = Lists.newArrayList();
    List<RepaymentPlanVO> repaymentPlans = Lists.newArrayList();
    private Boolean needUploadData = true;
    private Boolean needPayServiceFee = true;



    public Boolean getNeedPayServiceFee() {
        return needPayServiceFee;
    }

    public OrderConfirmDetailVO setNeedPayServiceFee(Boolean needPayServiceFee) {
        this.needPayServiceFee = needPayServiceFee;
        return this;
    }

    public Boolean getNeedUploadData() {
        return needUploadData;
    }

    public OrderConfirmDetailVO setNeedUploadData(Boolean needUploadData) {
        this.needUploadData = needUploadData;
        return this;
    }

    public String getMerchantCode() {
        return merchantCode;
    }

    public OrderConfirmDetailVO setMerchantCode(String merchantCode) {
        this.merchantCode = merchantCode;
        return this;
    }

    public PermissionsInfo getPermissionsInfo() {
        return permissionsInfo;
    }

    public OrderConfirmDetailVO setPermissionsInfo(PermissionsInfo permissionsInfo) {
        this.permissionsInfo = permissionsInfo;
        return this;
    }

    public String getProductCode() {
        return productCode;
    }

    public OrderConfirmDetailVO setProductCode(String productCode) {
        this.productCode = productCode;
        return this;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public OrderConfirmDetailVO setCategoryName(String categoryName) {
        this.categoryName = categoryName;
        return this;
    }

    public String getCategoryDesc() {
        return categoryDesc;
    }

    public OrderConfirmDetailVO setCategoryDesc(String categoryDesc) {
        this.categoryDesc = categoryDesc;
        return this;
    }

    public String getCategoryLogo() {
        return categoryLogo;
    }

    public OrderConfirmDetailVO setCategoryLogo(String categoryLogo) {
        this.categoryLogo = categoryLogo;
        return this;
    }

    public List<OrderFieldDetail> getOrderViewInfo() {
        return orderViewInfo;
    }

    public OrderConfirmDetailVO setOrderViewInfo(List<OrderFieldDetail> orderViewInfo) {
        this.orderViewInfo = orderViewInfo;
        return this;
    }

    public List<UsageOfLoan> getUsageOfLoanList() {
        return usageOfLoanList;
    }

    public OrderConfirmDetailVO setUsageOfLoanList(List<UsageOfLoan> usageOfLoanList) {
        this.usageOfLoanList = usageOfLoanList;
        return this;
    }

    public List<OrderFieldDetail> getOtherInfo() {
        return otherInfo;
    }

    public OrderConfirmDetailVO setOtherInfo(List<OrderFieldDetail> otherInfo) {
        this.otherInfo = otherInfo;
        return this;
    }

    public List<RepaymentPlanVO> getRepaymentPlans() {
        return repaymentPlans;
    }

    public OrderConfirmDetailVO setRepaymentPlans(List<RepaymentPlanVO> repaymentPlans) {
        this.repaymentPlans = repaymentPlans;
        return this;
    }

    public static List<OrderFieldDetail> convert2OrderViewInfo(OfferResponse offerResponse) {

        String period = offerResponse.getBorrowDurationEnum() == TradeBorrowDurationEnum.DAY ? offerResponse.getPeriodLength() + " Days"
                : offerResponse.getTotalPeriods() + "Months";
        OrderFieldDetail applyDate = new OrderFieldDetail("Apply Date", "1", new OrderFieldDetail.SchemeURL(DateUtil.getDate(new Date()), null));
        OrderFieldDetail amount = new OrderFieldDetail("Amount(₹)", "1", new OrderFieldDetail.SchemeURL(DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getBorrowTotalCapital())), null));
        OrderFieldDetail duration = new OrderFieldDetail("Duration", "1", new OrderFieldDetail.SchemeURL(period, null));
        List<OrderFieldDetail> orderFieldDetails = Lists.newArrayList();
        orderFieldDetails.add(applyDate);
        orderFieldDetails.add(amount);
        orderFieldDetails.add(duration);
        return orderFieldDetails;
    }

    public  static List<OrderFieldDetail> convert2OtherInfo(OfferResponse offerResponse, String bankCardNo, String agreementUrl, String bankConfirmTips,boolean isGpVersion) {

        OrderFieldDetail interest = new OrderFieldDetail("Interest", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getTotalInterestFee())), null));
        OrderFieldDetail serviceFees = new OrderFieldDetail("Service Fees", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getTotalServiceFee())), null));
        OrderFieldDetail gst = new OrderFieldDetail("GST", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getGstCharge())), null));
        OrderFieldDetail receiveAmount = new OrderFieldDetail("Amount You Get", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getReceivedTotalCapital())), null));
        OrderFieldDetail repaymentAmount = new OrderFieldDetail("Amount You Repay", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getPeriodRepaymentCapital())), null));
        OrderFieldDetail bankCard = new OrderFieldDetail("Bank Account No.", "7", bankConfirmTips, new OrderFieldDetail.SchemeURL(bankCardNo, JumpRouterEnum.PERSONAL_INFO_BANK.getJumpUrl()));
        OrderFieldDetail agreement = new OrderFieldDetail("Loan Agreement", "3", new OrderFieldDetail.SchemeURL("Loan Agreement", agreementUrl));
        List<OrderFieldDetail> orderFieldDetails = Lists.newArrayList();

        if (isGpVersion) {
            String interestContent = DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getTotalInterestFee()));
            interest = new OrderFieldDetail("Interest", "1", new OrderFieldDetail.SchemeURL("₹ " +interestContent+"("+offerResponse.getBorrowTotalCapital()+"x"+offerResponse.getBorrowRatio()+"x"+offerResponse.getPeriodLength()+"/365)", null));
            serviceFees = new OrderFieldDetail("Service Fees", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(0)), null));
            gst = new OrderFieldDetail("GST", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(0)), null));
            receiveAmount = new OrderFieldDetail("Amount You Get", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getBorrowTotalCapital())), null));
            repaymentAmount = new OrderFieldDetail("Amount You Repay", "1", new OrderFieldDetail.SchemeURL("₹ " + DecimalUtils.formatDecimal(new BigDecimal(offerResponse.getBorrowTotalCapital()).add(new BigDecimal(offerResponse.getTotalInterestFee()))), null));
        }

        orderFieldDetails.add(interest);

        orderFieldDetails.add(serviceFees);
        orderFieldDetails.add(gst);
        orderFieldDetails.add(receiveAmount);
        orderFieldDetails.add(repaymentAmount);
        orderFieldDetails.add(bankCard);
        orderFieldDetails.add(agreement);
        return orderFieldDetails;
    }
}
